package com.ds.client.support;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import com.ds.client.screen.InitGame;
import com.ds.server.RMIServerFramwork;
import com.ds.support.GameInfo;
import com.ds.support.GameStatus;

/**
 * this class is a local RMI object used to invoke remote RMI method
 */
public class ServerStub {
	public  RMIServerFramwork rService;
	public ServerStub() throws MalformedURLException, RemoteException, NotBoundException{
			 RMIServerFramwork tmp = null; 
			tmp = (RMIServerFramwork) Naming.lookup("rmi://localhost:8888/RService");
			   rService = tmp;
		}
	
	
    public  int register(int carType) throws RemoteException {
    	int carID = 0;
        	carID = rService.register(carType); 	
    	return carID;
    }
    
    public  void moveCar(int carID, String move) throws RemoteException {
//    	GameInfo gameInfo = null;
//    	System.out.println("move: " + move);
    		rService.moveCar(carID, move);

//    	return gameInfo;
    }
    
    public  GameInfo getGameInfo() throws RemoteException {
    	GameInfo gameInfo = null;
        gameInfo = rService.getGameInfo();
    	return gameInfo;
    }
    
    public  GameStatus getGameStatus(int carID) throws RemoteException {
    	GameStatus gameStatus = null;
    	gameStatus = rService.getGameStatus(carID);
    	return gameStatus;
    }
    
    public  int getWinner() throws RemoteException {
    	int winner = -1;
    	winner = rService.getWinner();
    	return winner;
    }
    
    public  void removeMyself(int carID) throws RemoteException {
    	rService.removeMyself(carID);

    }
}